import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;


public class MyClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		Socket s = new Socket("127.0.0.1", 42083);
		PrintWriter out = new PrintWriter(s.getOutputStream(), true);
		String req = "20111";
		System.out.println("Requesting string:" + req);
		out.println(req);
		byte[] data = new byte[16];
		InputStream inputStream = s.getInputStream();
		int count = inputStream.read(data);
		System.out.println("value is " + ByteBuffer.wrap(data).getDouble());
		
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("zw.jpg"));
		BufferedInputStream bis = new BufferedInputStream(inputStream);
		byte[] content = new byte[1024];
		int r; 
		int bytesRead = 0;
		while( (r = bis.read(content)) != -1){
			bos.write(content, 0, r);
			bytesRead+=r;
			if(bytesRead == 250880){
				System.out.println(r);
			}
		}
		bos.close();
		System.out.println(bytesRead);
	}

}
